#include "StdAfx.h"
#include "FIT_6204_Gorodilov_Rect.h"

CFIT_6204_Gorodilov_Rect::CFIT_6204_Gorodilov_Rect(void)
{
}

CFIT_6204_Gorodilov_Rect::~CFIT_6204_Gorodilov_Rect(void)
{
}

const CFIT_6204_Gorodilov_Point CFIT_6204_Gorodilov_Rect::left(void) const {
	for (int i = 0; i < 2; i++) {
		if (points[i].getPointType() == RECT_POINT_LEFT) {
			return points[i];
		}
	}
	return CFIT_6204_Gorodilov_Point();
};

const CFIT_6204_Gorodilov_Point CFIT_6204_Gorodilov_Rect::right(void) const {
	for (int i = 0; i < 2; i++) {
		if (points[i].getPointType() == RECT_POINT_RIGHT) {
			return points[i];
		}
	}
	return CFIT_6204_Gorodilov_Point();
};

CFIT_6204_Gorodilov_Point& CFIT_6204_Gorodilov_Rect::left(void) {
	for (int i = 0; i < 2; i++) {
		if (points[i].getPointType() == RECT_POINT_LEFT) {
			return points[i];
		}
	}	
	int resultIndex = 0;
	for (int i = 0; i < 2; i++) {
		if (points[i].x() < points[resultIndex].x()) {
			resultIndex = i;
		}
	}
	points[resultIndex].setPointType(RECT_POINT_LEFT);
	return points[resultIndex];
};

CFIT_6204_Gorodilov_Point& CFIT_6204_Gorodilov_Rect::right(void) {
	for (int i = 0; i < 2; i++) {
		if (points[i].getPointType() == RECT_POINT_RIGHT) {
			return points[i];
		}
	}
	int resultIndex = 0;
	for (int i = 0; i < 2; i++) {
		if (points[i].x() >= points[resultIndex].x()) {
			resultIndex = i;
		}
	}
	points[resultIndex].setPointType(RECT_POINT_RIGHT);
	return points[resultIndex];
};